package com.wzz.common.calendar.views;

import android.graphics.Rect;
import android.util.MonthDisplayHelper;

import com.wzz.common.calendar.views.cells.BlueCell;
import com.wzz.common.calendar.views.cells.GrayCell;
import com.wzz.common.calendar.views.cells.RedCell;

public class CellFactory {
  @SuppressWarnings("unused")
  private static final String TAG = "CellFactory";

  private static volatile CellFactory instance;
  private static float textSize = 0f;
  private MonthDisplayHelper helper;
  public static final int RED = 0;
  public static final int BLUE = 1;
  public static final int GRAY = 2;
  public static final int NONE = -1;

  private CellFactory(float textSize) {
    CellFactory.textSize = textSize;
  }

  public static CellFactory getInstance(float textSize) {
    if (instance == null) {
      synchronized (CellFactory.class) {
        if (instance == null) {
          instance = new CellFactory(textSize);
        }
      }
    }
    return instance;
  }
  
  public void setHelper(MonthDisplayHelper helper){
    this.helper = helper;
  }

  public Cell create(int type, int day, Rect bound) {
    Cell cell = null;
    switch (type) {
      case RED:
        cell = new RedCell(day, new Rect(bound), textSize);
        break;
      case BLUE:
        cell = new BlueCell(day, new Rect(bound), textSize);
        break;
      case GRAY:
        cell = new GrayCell(day, new Rect(bound), textSize);
        cell.isThisMonth = false;
        break;
      default:
        cell = new Cell(day, new Rect(bound), textSize);
        break;
    }
    
    cell.setMonth(helper.getMonth());
    cell.setYear(helper.getYear());
    
    return cell;
  }

}
